package jhlee42.swing;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Arrays;

import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.LookAndFeel;
import javax.swing.UIManager;
import javax.swing.border.EmptyBorder;
import javax.swing.table.DefaultTableModel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter.DEFAULT;

public class CoupleMaker extends JFrame {

	protected static final LookAndFeel MetalLook = null;
	private JPanel contentPane;
	private JTextField uid;
	private JPasswordField pwd;
	private JTable table;
	private JTable table_1;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					
					
					
					
					
					// 룩앤필 변경 시작 9
					JFrame.setDefaultLookAndFeelDecorated(true);
					UIManager.setLookAndFeel(MetalLook);
					// 룩앤필 변경 끝 9
					
					
					
					
					
					CoupleMaker frame = new CoupleMaker();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public CoupleMaker() {
		setTitle("연인 만들기");
		setSize(new Dimension(454, 304));
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 800, 600);
		setLocationRelativeTo(null); // 2
		
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(new BorderLayout(0, 0));
		
		JPanel panel = new JPanel();
		panel.setPreferredSize(new Dimension(800, 100));
		contentPane.add(panel, BorderLayout.NORTH);
		panel.setLayout(new BorderLayout(0, 0));
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
/******************************************************************************************/			
		
		
		
		
		
		JPanel panel_4 = new JPanel();
		panel_4.setBackground(Color.YELLOW);
		panel_4.setPreferredSize(new Dimension(200, 100));
		panel.add(panel_4, BorderLayout.EAST);
		
		uid = new JTextField();
		uid.setText("아이디");
		uid.setToolTipText("아이디를 입력하세요.");
		uid.setColumns(10);
		
		
		
		
		final JButton joinBtn = new JButton("회원가입");
		
		pwd = new JPasswordField();
		pwd.setToolTipText("비밀번호를 입력하세요.");
		
		
		
		
		final JButton logInBtn = new JButton("로그인");
		logInBtn.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				if(logInBtn.getText().equals("로그인")){
					if(uid.getText().equals("1")&& Arrays.equals("1".toCharArray(), pwd.getPassword())){
						JOptionPane.showMessageDialog(null, "로그인 성공!!");
						logInBtn.setText("로그아웃");
						joinBtn.setVisible(false);
					}
					else{
						JOptionPane.showMessageDialog(null, "로그인 실패!!");
					}
				}
				else if(logInBtn.getText().equals("로그아웃")){
					JOptionPane.showMessageDialog(null, "로그아웃 성공");
					logInBtn.setText("로그인");
					joinBtn.setVisible(true);
				}

			}
		});
		

		
		

		
		GroupLayout gl_panel_4 = new GroupLayout(panel_4);
		gl_panel_4.setHorizontalGroup(
			gl_panel_4.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panel_4.createSequentialGroup()
					.addContainerGap()
					.addGroup(gl_panel_4.createParallelGroup(Alignment.LEADING, false)
						.addComponent(pwd)
						.addComponent(uid, GroupLayout.DEFAULT_SIZE, 86, Short.MAX_VALUE))
					.addPreferredGap(ComponentPlacement.RELATED)
					.addGroup(gl_panel_4.createParallelGroup(Alignment.LEADING, false)
						.addComponent(logInBtn, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
						.addComponent(joinBtn, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
					.addGap(14))
		);
		gl_panel_4.setVerticalGroup(
			gl_panel_4.createParallelGroup(Alignment.TRAILING)
				.addGroup(gl_panel_4.createSequentialGroup()
					.addContainerGap(28, Short.MAX_VALUE)
					.addGroup(gl_panel_4.createParallelGroup(Alignment.BASELINE)
						.addComponent(uid, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(logInBtn))
					.addPreferredGap(ComponentPlacement.RELATED)
					.addGroup(gl_panel_4.createParallelGroup(Alignment.BASELINE)
						.addComponent(joinBtn)
						.addComponent(pwd, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addGap(20))
		);
		panel_4.setLayout(gl_panel_4);
		
/******************************************************************************************/			
		
		
		
		
		
		
		
		
		
		
		JLabel lblNewLabel = new JLabel("");
		lblNewLabel.setIcon(new ImageIcon(CoupleMaker.class.getResource("/images/background/top.jpg")));
		panel.add(lblNewLabel, BorderLayout.WEST);
		
		JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
		contentPane.add(tabbedPane, BorderLayout.CENTER);
		
		JPanel panel_1 = new JPanel();
		tabbedPane.addTab("New tab", null, panel_1, null);
		
		JScrollPane scrollPane = new JScrollPane();
		scrollPane.setPreferredSize(new Dimension(500, 200));
		panel_1.add(scrollPane);
		
		table = new JTable();
		table.setPreferredSize(new Dimension(500, 200));
		scrollPane.setViewportView(table);
		
		JPanel panel_2 = new JPanel();
		tabbedPane.addTab("New tab", null, panel_2, null);
		
		
		
		
		JScrollPane scrollPane_1 = new JScrollPane();
		scrollPane_1.setPreferredSize(new Dimension(500, 200));
		panel_2.add(scrollPane_1);
		
		// 성적 데이터 생성
		ArrayList<SungJuk2VO> sjlist = new ArrayList<>();
		sjlist.add(new SungJuk2VO("태희",100,99,98 ));
		sjlist.add(new SungJuk2VO("지현",100,99,98 ));
		sjlist.add(new SungJuk2VO("수지",100,99,98 ));
		sjlist.add(new SungJuk2VO("종현",0,0,10 ));

//		Jtable에 배열 데이터를 저장하기 위해
//		DefaultTableModel 를 작성
		DefaultTableModel model = new DefaultTableModel();
		// 테이블의 제목줄에 사용할 항목 지정
		model.setColumnIdentifiers(
				new String[] {"이름","국어","영어","수학"}
				
				
				
				);
		
		// 테이블의 본문행을 작성
		for(SungJuk2VO sj:sjlist){
			model.addRow(new String[]{
					sj.getName(),sj.getKor()+"",sj.getEng()+"",sj.getMat()+""
					
					
					
			});
		}
		
		// 생성한 모델을 JTable 생성자의 인자로 전달
		//table = new JTable(model);
		
		
		
		table_1 = new JTable(model);
		table_1.setPreferredSize(new Dimension(500, 200));
		scrollPane_1.setViewportView(table_1);
		
		JPanel panel_3 = new JPanel();
		tabbedPane.addTab("New tab", null, panel_3, null);
	}
}



















